"""
@File    :   simulate_input_data.py
@Time    :   2024/03/20 16:15:40
@Author  :   glx 
@Version :   1.0
@Contact :   18095542g@connect.polyu.hk
@Desc    :   None
"""

import sys
from pathlib import Path

sys.path.append(str(Path(__file__).parent.parent))  # add parent dir to sys path

# here put the import lib
from typing import List, Dict
import numpy as np
import random
from copy import deepcopy
import excel2json as e2j
import build_signal_sample as bs

from src.main import main
import pandas as pd
import json

# random.seed(0)
random_state = 2
simu_url = "simu_folder"
simu_folder = Path(simu_url)
simu_folder.mkdir(exist_ok=True)

# 1. simulate the input data
static_tan_threshold = 2
stabel_tan_range_threshold = 30
tan_step = 50
diff_step = 20

tan_degree_list = bs.generate_tan_list(
    fast_num=20,
    stabel_num=5,
    static_num=5,
    threshold=(static_tan_threshold, stabel_tan_range_threshold),
)
data = bs.build_total_signal_sample(
    start=0,
    tan_var=50,
    diff_var=30,
    tan_degree_list=tan_degree_list,
    diff_list=[-60, 60],
    tan_step=tan_step,
    diff_step=diff_step,
)
# save the data to csv
df = pd.DataFrame(data)
df.to_csv(
    rf"{simu_url}\{static_tan_threshold}_{stabel_tan_range_threshold}.csv",
    index=False,
    header=False,
)

# make input data
with open(r"data\pattern.json", "r") as f:
    pattern = json.load(f)

pattern["config"]["TAN_RANGE"] = [stabel_tan_range_threshold, 90]
pattern["config"]["ST"] = static_tan_threshold
pattern["config"]["FAST_STEP"] = tan_step
pattern["config"]["SLOW_STEP"] = tan_step

json_data = e2j.trans_DATA_json(data, pattern)
with open(
    rf"{simu_url}\{static_tan_threshold}_{stabel_tan_range_threshold}_{random_state}.json",
    "w",
) as f:
    json.dump(json_data, f, indent=4)


# mr the input data
main(
    json_data,
    simu_folder
    / rf"{static_tan_threshold}_{stabel_tan_range_threshold}_{random_state}_output.json",
)
